package pers.cz;

import pers.cz.config.Config;
import pers.cz.config.ConfigCache;
import pers.cz.tools.DynamicCompilationUtil;
import pers.cz.tools.JavaFileAnaylize;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;

/**
 * @program: PostGirl-panent
 * @description: Application
 * @author: Cheng Zhi
 * @create: 2022-05-19 20:12
 **/
public class Application {

    static {

        Properties properties = null;
        try {
            properties = ConfigCache.getProperties();
            ConfigCache.setConfig(properties);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        Map<String, String> cacheMap = Config.getConfig().getsysConfig();

        if (args.length == 0) {
            System.out.println("请输入正确的文件");
            return;
        }
        //String filePath = cacheMap.get("java_file_path");
        String filePath = args[0];
        String jarPath = cacheMap.get("rely_lib");
        String isSave = cacheMap.get("isSave");
        String saveCalssPath = "";
        if ("true".equals(isSave)) {
            saveCalssPath = cacheMap.get("save_path");
        }
        File file = new File(filePath);
        String fileName = file.getName();
        String[] split = fileName.split("\\."); // 要去掉后缀
        fileName = split[0];
        //fileName = "QueryBillExtNewBusiness";
        String javaScript = JavaFileAnaylize.anayLizeFile(file);
        DynamicCompilationUtil dynamicCompilationUtil = new DynamicCompilationUtil();

        String s = dynamicCompilationUtil.compileJava(javaScript, jarPath, saveCalssPath, fileName);

    }
}
